package satk.beans.request;

import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.DataModel;
import satk.objetos.Evento;
import satk.tools.SortedPack;

/**
 * <h3>AllEventosBean.java</h3>
 * <div><em>Fecha de creación: 1/05/2011, 10:36:14 PM.</em></div>
 * <p></p>
 * @author Sergio Flores Genis <sf.cancun@gmail.com>
 */
@ManagedBean
@RequestScoped
public class AllEventosBean implements Serializable {

    private static final long serialVersionUID = 520646741L;
    public java.util.List<Evento> lista = null;
    public DataModel<Evento> dataModel = null;

    public AllEventosBean() {
        this.lista = new satk.database.ManagerEvento().getAll();
        this.dataModel = new javax.faces.model.ListDataModel<Evento>(lista);
    }

    public List<Evento> getLista() {
        return lista;
    }
    public DataModel<Evento> getDataModel() {
        return dataModel;
    }
    public List<SortedPack<Evento>> getEventosPorAnio() {
        java.util.LinkedList<SortedPack< Evento>> listPack;
        listPack = new java.util.LinkedList<SortedPack<Evento>>();
        for (Evento e : lista) {
            String anio = String.valueOf(e.getAnio());
            boolean registrado = false;
            for (SortedPack<Evento> sortedPack : listPack) {
                if (sortedPack.getClave().equals(anio)) {
                    sortedPack.add(e);
                    registrado = true;
                    break;
                }
            } // END FOR [listPack]
            if (!registrado) {
                listPack.add(new SortedPack<Evento>(anio));
                listPack.getLast().add(e);
            }
        } // END FOR [eventos]

        java.util.Collections.sort(listPack, new SortedPack.ComparatorSortedPack());
        for (SortedPack<Evento> sortedPack : listPack) {
            java.util.Collections.sort(sortedPack, new satk.tools.ComparatorEvento());
        }
        return listPack;
    }
}
